import Taro from "@tarojs/taro";
import { ComponentClass } from "react";
import { Text, View } from "@tarojs/components";
import "./index.sass";

type ComponentStateProps = {};

type ComponentOwnProps = {
  top: number;
  renderLeft: any;
  children: any;
  color?: string;
};

type IProps = ComponentStateProps & ComponentOwnProps;

interface Title {
  props: IProps;
}

class Title extends Taro.Component {
  static defaultProps = {
    color: "#fff"
  };

  componentWillReceiveProps(nextProps) {
    // 控制是否更新视图
  }

  render() {
    const { top, color } = this.props;
    return (
      <View className="title-wrap" style={{ top: `${top} px` }}>
        <View className="left">{this.props.renderLeft}</View>
        <Text style={{ color }}>{this.props.children}</Text>
      </View>
    );
  }
}

export default Title as ComponentClass<ComponentOwnProps, ComponentStateProps>;
